

package View;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 *
 * @author CCD gruppe 2
 */
public class WelcomeTabPanel extends javax.swing.JPanel {

    private javax.swing.JLabel ccdLogoLabel;
    private javax.swing.JLabel dateForSessionLabel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel preparationLabel;
    private javax.swing.JTextArea preparationTextArea;
    private javax.swing.JLabel sessionDateLabel;
    private javax.swing.JPanel sessionPreparationPanel;
    private javax.swing.JLabel theNextSessionIsLabel;
    private javax.swing.JLabel todaysDateLabel;
    private javax.swing.JLabel userRoleLabel;
    private javax.swing.JLabel welcomeMsgLabel;
    private javax.swing.JLabel yourRoleLabel;
    private String todaysDate = "";
    private String sessionsDate = "";
    SimpleDateFormat dateFormat;

    public WelcomeTabPanel() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        welcomeMsgLabel = new javax.swing.JLabel();
        ccdLogoLabel = new javax.swing.JLabel();
        todaysDateLabel = new javax.swing.JLabel();
        theNextSessionIsLabel = new javax.swing.JLabel();
        sessionPreparationPanel = new javax.swing.JPanel();
        yourRoleLabel = new javax.swing.JLabel();
        userRoleLabel = new javax.swing.JLabel();
        preparationLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        preparationTextArea = new javax.swing.JTextArea();
        dateForSessionLabel = new javax.swing.JLabel();
        sessionDateLabel = new javax.swing.JLabel();

        dateFormat = new SimpleDateFormat("dd.MM.yyyy");
        Date date = new Date();
        todaysDate = dateFormat.format(date);
        setMinimumSize(new java.awt.Dimension(746, 462));
        setMaximumSize(new java.awt.Dimension(746, 462));

        setPreferredSize(new java.awt.Dimension(746, 462));

        welcomeMsgLabel.setText("Velkommen <brukernavn>. ");

        ccdLogoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/Logo1_smallerpng.png"))); // NOI18N

        todaysDateLabel.setText("Dagens dato: " + todaysDate);

        theNextSessionIsLabel.setText("Den neste sesjonen er: <sesjonsnavn> i prosjektet <prosjektnavn>.");

        sessionPreparationPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("<SesjonsNavn>"));

        yourRoleLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        yourRoleLabel.setText("Din rolle:");

        preparationLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        preparationLabel.setText("Forberedelse:");

        preparationTextArea.setColumns(20);
        preparationTextArea.setEditable(false);
        preparationTextArea.setRows(5);
        preparationTextArea.setLineWrap(true);
        preparationTextArea.setFocusable(false);
        jScrollPane1.setViewportView(preparationTextArea);

        dateForSessionLabel.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        dateForSessionLabel.setText("Dato for sesjon:");

        sessionDateLabel.setText(sessionsDate);
        sessionPreparationPanel.setVisible(false);
        welcomeMsgLabel.setVisible(false);
        theNextSessionIsLabel.setVisible(false);
        ccdLogoLabel.setVisible(false);
        todaysDateLabel.setVisible(false);

        org.jdesktop.layout.GroupLayout sessionPreparationPanelLayout = new org.jdesktop.layout.GroupLayout(sessionPreparationPanel);
        sessionPreparationPanel.setLayout(sessionPreparationPanelLayout);
        sessionPreparationPanelLayout.setHorizontalGroup(
            sessionPreparationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sessionPreparationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(sessionPreparationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
                    .add(preparationLabel)
                    .add(sessionPreparationPanelLayout.createSequentialGroup()
                        .add(yourRoleLabel)
                        .add(159, 159, 159)
                        .add(dateForSessionLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(sessionDateLabel))
                    .add(userRoleLabel))
                .addContainerGap())
        );
        sessionPreparationPanelLayout.setVerticalGroup(
            sessionPreparationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sessionPreparationPanelLayout.createSequentialGroup()
                .add(sessionPreparationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(yourRoleLabel)
                    .add(dateForSessionLabel)
                    .add(sessionDateLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(userRoleLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(preparationLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(sessionPreparationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(welcomeMsgLabel))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(todaysDateLabel)
                            .add(ccdLogoLabel)))
                    .add(theNextSessionIsLabel)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 745, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(welcomeMsgLabel)
                    .add(todaysDateLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(200, 200, 200)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE)
                        .add(ccdLogoLabel))
                    .add(layout.createSequentialGroup()
                        .add(18, 18, 18)
                        .add(theNextSessionIsLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 33, Short.MAX_VALUE)
                        .add(sessionPreparationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>


    /**
     * A method that hides the nearest session info
     * @param userName
     */
    public void hideSessionInfo(String userName){
        welcomeMsgLabel.setText("Velkommen "+userName+".");
        theNextSessionIsLabel.setText("Du er ikke registrert i noen sesjoner.");
        sessionPreparationPanel.setVisible(false);
        welcomeMsgLabel.setVisible(true);
        theNextSessionIsLabel.setVisible(true);
        ccdLogoLabel.setVisible(true);
        todaysDateLabel.setVisible(true);
    }

    /*
     * Getters and setters
     */
    public JLabel getCcdLogoLabel() {
        return ccdLogoLabel;
    }

    public JLabel getDateForSessionLabel() {
        return dateForSessionLabel;
    }

    public JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    public JLabel getPreparationLabel() {
        return preparationLabel;
    }

    public JTextArea getPreparationTextArea() {
        return preparationTextArea;
    }

    public JLabel getSessionDateLabel() {
        return sessionDateLabel;
    }

    public JPanel getSessionPreparationPanel() {
        return sessionPreparationPanel;
    }

    public JLabel getTheNextSessionIsLabel() {
        return theNextSessionIsLabel;
    }

    public JLabel getTodaysDateLabel() {
        return todaysDateLabel;
    }

    public JLabel getUserRoleLabel() {
        return userRoleLabel;
    }

    public JLabel getWelcomeMsgLabel() {
        return welcomeMsgLabel;
    }

    public JLabel getYourRoleLabel() {
        return yourRoleLabel;
    }

    public void setSessionInfo(String userName, String date, String sessionName, String projectName, String preparationInfo, ArrayList<String> userRole) {
        String roles = "";
        if (userRole.size() == 1) {
            roles = userRole.get(0);
        } else if (userRole.isEmpty()) {
            roles = "Ekspert";
        } else {
            roles = userRole.get(0);
            for (int i = 1; i < userRole.size(); i++) {
                roles += ", " + userRole.get(i);
            }
        }

        sessionPreparationPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(sessionName));
        userRoleLabel.setText(roles);
        welcomeMsgLabel.setText("Velkommen " + userName + ".");
        sessionDateLabel.setText(date);
        preparationTextArea.setText(preparationInfo);
        theNextSessionIsLabel.setText("Den neste sesjonen er: " + sessionName + " i prosjektet " + projectName + ".");
        sessionPreparationPanel.setVisible(true);
        theNextSessionIsLabel.setVisible(true);
        welcomeMsgLabel.setVisible(true);
        ccdLogoLabel.setVisible(true);
        todaysDateLabel.setVisible(true);

    }




}
